package com.an.groupecho;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;

public class MyClientHandler extends ChannelInboundHandlerAdapter{

	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {

		System.out.println("ctx: "+ ctx);
		ctx.writeAndFlush(Unpooled.copiedBuffer("我是客户端 哦        ！！！！！--->>>>" ,CharsetUtil.UTF_8));

	}
	
	
	// tongdao通道有读取事件是，触发
	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
		System.out.println("服务器回复消息：：：" + msg);
		System.out.println("服务器地址：" + ctx.channel().remoteAddress());
		
	}
	
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		
		// 打印异常信息
		cause.printStackTrace();
		ctx.close();
	}

}
